import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main2 {

    public static int n;
    public static Queue<int[]> queue = new LinkedList<>();
    public static boolean[][] flag;
    public static int[] dx = new int[]{1, -1, 0, 0};
    public static int[] dy = new int[]{0, 0, 1, -1};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        int[][] arr = new int[n][n];
        flag = new boolean[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                arr[i][j] = sc.nextInt();
                if ((i == 0 || i == n - 1 || j == 0 || j == n - 1) && arr[i][j] == 0) {
                    flag[i][j] = true;
                    queue.offer(new int[]{i, j});
                }
            }
        }

        bfs(arr);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (arr[i][j] == 0) {
                    arr[i][j] = 2;
                }
                if (arr[i][j] == -1) {
                    arr[i][j] = 0;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }

        sc.close();
    }

    public static void bfs(int[][] arr) {

        while (!queue.isEmpty()) {
            int size = queue.size();
            while (size > 0) {
                size--;
                int[] arr1 = queue.poll();
                int x = arr1[0];
                int y = arr1[1];
                flag[x][y] = true;
                arr[x][y] = -1;
                for (int i = 0; i < 4; i++) {
                    int xx = x + dx[i];
                    int yy = y + dy[i];
                    if (xx >= 0 && xx < n && yy >= 0 && yy < n && !flag[xx][yy] && arr[xx][yy] == 0) {
                        flag[xx][yy] = true;
                        arr[xx][yy] = -1;
                        queue.offer(new int[]{xx, yy});
                    }
                }
            }
        }
    }
}
